﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZS_AddPCHInfoControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        Label 征收决定号, Label1, Label2, Label3;
        TextBox txt征收批次号, txtID, txtPNID, txtPCID, txt首次;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            InitControl();
            MPPersistence Persistence1 = (MPPersistence)FindControl("Persistence1");
            Panel panel1 = (Panel)FindControl("panel1");
            if (!base.Page.IsPostBack)
            {
                Persistence1.Table = "ZS_ZSPCH";
                Persistence1.Key = "ID";
                Persistence1.KeyValue = HttpContext.Current.Request["id"];
                Persistence1.ConnStr = _EluZSDataProvider.GetConnectionString();
                
            }
            Persistence1.BindControl = panel1;
            BindData();
            Button btn_Insert = (Button)FindControl("btn_Insert");
            btn_Insert.Click += btnSave_Click;
            IsLookPerson();
        }

        private void IsLookPerson()
        {
            string sql = "Select rolename from zs_role where id in (Select roleid from zs_user_in_role where userid = '" + userid + "')";
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["rolename"].ToString().Equals("查看人员"))
                    {
                        Button btnSave = (Button)FindControl("btnSave");
                        btnSave.Visible = false;
                    }
                }
            }
        }


        protected void InitControl() {
            征收决定号 = (Label)FindControl("征收决定号");
            Label1 = (Label)FindControl("Label1");
            Label2 = (Label)FindControl("Label2");
            Label3 = (Label)FindControl("Label3");

            txt征收批次号 = (TextBox)FindControl("txt征收批次号");
            txtID = (TextBox)FindControl("txtID");
            txtPNID = (TextBox)FindControl("txtPNID");
            txtPCID = (TextBox)FindControl("txtPCID");
            txt首次 = (TextBox)FindControl("txt首次");
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            string pnid = base.Page.Request["PNID"];
            txtPNID.Text = pnid;
            txtPCID.Text = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper();
            txtID.Text = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper();
            if (!string.IsNullOrEmpty(pnid)) {
                string zsjdh = _EluZSDataProvider.GetSomeStr("zs_prono", "征收许可证号", "id", pnid);
                if (!string.IsNullOrEmpty(zsjdh)) {
                    征收决定号.Text = zsjdh;
                    Label1.Text = zsjdh;
                }
                int tt =Convert.ToInt32(_EluZSDataProvider.GetSomeStr("ZS_ZSPCH", "count(distinct pcid)", "pnid", pnid));
                if (tt == 0) {
                    Label3.Text = "1";
                    txt首次.Text = "1";
                }
                else if (tt > 0) {
                    Label3.Text = (tt + 1).ToString();
                }
            }
        }
        protected void BindData() {
            
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            MPPersistence Persistence1 = (MPPersistence)FindControl("Persistence1");
            Persistence1.Update();
            HttpContext.Current.Response.Redirect("ZS_AddPCHIN.aspx?PNID=" + base.Page.Request["PNID"]);
        }
    }
}


